/*
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 *
 * Copyright @2008 the original author or authors.
 */
package com.bluestone.core;

import java.util.ArrayList;

/**
 * A page contains some elements.
 * @author <a href="mailto:bluestone.daniel.q@gmail.com">daniel.q</a>
 * 
 */
public class Page {

	private Object parent;

	private String name;

	private String browserBar = "TRUE";

	private ArrayList elements;
	
	private String owner;

	/**
	 * Add an element to page.
	 * @param element
	 */
	public void addElement(Element element) {
		elements.add(element);
	}

	/**
	 * All of the elements in the page.
	 * @return elements - ArrayList
	 */
	public ArrayList getElements() {
		return elements;
	}

	public void setElements(ArrayList elements) {
		this.elements = elements;
	}

	/**
	 * The name of the page.
	 * @return name - String
	 */
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String toString() {
		String str = "page:";
		if (name != null) {
			str = str + "" + name;
		}
		if (browserBar != null) {
			str = str + ",browserBar=" + browserBar;
		}
		return (str);

	}

	/**
	 * Indicate whether to display the toolBar of the browser or not.
	 * @return  
	 */
	public String getBrowserBar() {
		return browserBar;
	}

	public void setBrowserBar(String browserBar) {
		this.browserBar = browserBar;
	}

	public Object getParent() {
		return parent;
	}

	public void setParent(Object parent) {
		this.parent = parent;
	}

	/**
	 * The path of the page.
	 * @return path - String
	 */
	public String getSearchPath() {
		String path = "";
		if (parent != null) {
			path = ((Module) parent).getSearchPath();
		}
		path = path + "|" + name;
		return path;
	}

	public String getOwner() {
		return owner;
	}

	public void setOwner(String owner) {
		this.owner = owner;
	}
	
	/**
	 * According the forward to find an element.
	 * @param forward
	 * @return
	 */
	public Element searchForward(String forward){
		Element element = null;
		for(int i=0; i< elements.size(); i++){
			Element e = (Element)elements.get(i);
			if(e.getForward()!=null && e.getForward().indexOf(forward)>=0){
				element = e;
				break;
			}
		}
		return element;
	}

}
